//
// core - server core source code.
//
// $Rev$
// $Author$
// $Date$
//
// Define class BoundQueue.
// Muti-thread safe.
//

#ifndef __BOUND__QUEUE__H
#define __BOUND__QUEUE__H

#include "core/base/bound_queue_common.h"
#include "core/base/byte_buffer_static.h"
#include "core/base/condition_variable.h"
#include "core/base/mutex.h"
#include "core/base/noncopyable.h"

namespace core {

class BoundQueue : public Noncopyable {
 public:
  BoundQueue(size_t max_size, int blocking_pattern);
  ~BoundQueue();

  int Add(const char *data, size_t size);
  int Remove(char *data, size_t size);

 private:
  // The queue.
  ByteBufferStaticMalloc queue_;
  size_t size_;

  volatile size_t write_pointer_;
  volatile size_t read_pointer_;

  mutable Mutex mutex_not_empty_;
  mutable Mutex mutex_not_full_;
  ConditionVariable condition_not_empty_;
  ConditionVariable condition_not_full_;

  int blocking_pattern_;
};

}  // namespace core

#endif  // __BOUND__QUEUE__H

